package com.sg.service.biz.pbff.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.pbff.req.BffImplementUnstructuredRelationshipCompDocNameReqDto;
import com.sg.dto.biz.pbff.res.BffImplementUnstructuredRelationshipCompDocNameRespDto;
import com.sg.dto.integration.component.ImplementUnstructuredRelationshipCompDocNameComReqDto;
import com.sg.dto.integration.component.ImplementUnstructuredRelationshipCompDocNameComRespDto;
import com.sg.dto.integration.component.QueryDocumentListComReqDto;
import com.sg.dto.integration.component.QueryDocumentListComRespDto;
import com.sg.service.biz.pbff.UnstructuredDataService;
import com.wicket.okrcomponent.integration.UnstructuredDataService;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class UnstructuredDataServiceImpl implements UnstructuredDataService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    com.sg.service.biz.component.UnstructuredDataService fwCompUnstructuredDataClient;

    /**
     * B2执行文档关系补偿文档名称（运维接口）[10055]
     * gen by moon at 8/6/2024, 7:55:36 PM
     */
    @Trace(operationName = "B2执行文档关系补偿文档名称（运维接口）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffImplementUnstructuredRelationshipCompDocNameRespDto implementUnstructuredRelationshipCompDocName(BffImplementUnstructuredRelationshipCompDocNameReqDto reqDto) {


        //virtualUsage D2查询文档列表(公共)  71990
        QueryDocumentListComRespDto queryDocumentListComRespDto = null;
        QueryDocumentListComReqDto queryDocumentListComReqDto = new QueryDocumentListComReqDto();
        if (reqDto != null) {
            queryDocumentListComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1956422_1_71990
        }

        /*D2查询文档列表(公共)[10056]   */
        Assert.isNull(queryDocumentListComReqDto.getSpaceId(), "B2执行文档关系补偿文档名称（运维接口）-D2查询文档列表(公共)-创建于空间ID不能为空", false);
        queryDocumentListComRespDto = fwCompUnstructuredDataClient.queryDocumentListCom(queryDocumentListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        if ((queryDocumentListComRespDto != null && queryDocumentListComRespDto.getDocumentList() != null && queryDocumentListComRespDto.getDocumentList().size() > 0)) {
            //if(D2查询空间下所有文档列表(公共).文档列表数据集条数 大于 0)  71991

            ImplementUnstructuredRelationshipCompDocNameComRespDto implementUnstructuredRelationshipCompDocNameComRespDto = null;
            if (queryDocumentListComRespDto != null) {
                ImplementUnstructuredRelationshipCompDocNameComReqDto implementUnstructuredRelationshipCompDocNameComReqDto = new ImplementUnstructuredRelationshipCompDocNameComReqDto();
                if (queryDocumentListComRespDto != null && queryDocumentListComRespDto.getDocumentList() != null && !CollectionUtil.isEmpty(queryDocumentListComRespDto.getDocumentList())) {
                    implementUnstructuredRelationshipCompDocNameComReqDto.setDocumentList(queryDocumentListComRespDto.getDocumentList().stream().map(item -> item.getUnstructuredDataId())
                            .collect(Collectors.toList()));/*list-to-strings*///sourceId:1956424_1_71992
                }
                if (reqDto != null) {
                    implementUnstructuredRelationshipCompDocNameComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1956425_1_71992
                }

                /*D2执行文档关系补偿文档名称(公共)[10053]   */
                Assert.isNull(implementUnstructuredRelationshipCompDocNameComReqDto.getSpaceId(), "B2执行文档关系补偿文档名称（运维接口）-D2执行文档关系补偿文档名称(公共)-创建于空间ID不能为空", false);
                implementUnstructuredRelationshipCompDocNameComRespDto = fwCompUnstructuredDataClient.implementUnstructuredRelationshipCompDocNameCom(implementUnstructuredRelationshipCompDocNameComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


            }
        }
        BffImplementUnstructuredRelationshipCompDocNameRespDto retData = new BffImplementUnstructuredRelationshipCompDocNameRespDto();


        return retData;
    }
    //
}
